import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from vmdpy import VMD
plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False    # 解决负号显示问题
# 读取数据
data = pd.read_csv("E:/GraduateDesign/LinearUse.csv")  # 没有列名
x = data['rrr'].values  # 假设第0列是降水量数据（你可以换成别的列）

# 执行VMD
alpha = 5000
tau = 0.
K = 6
DC = 0
init = 1
tol = 1e-7

u, u_hat, omega = VMD(x, alpha, tau, K, DC, init, tol)

# 绘图
fig, axs = plt.subplots(K, 1, figsize=(14, 10), sharex=True)
for i in range(K):
    axs[i].plot(u[i], color='red')
    axs[i].set_ylabel(f'IMF{i+1}')
    axs[i].grid(True)
plt.xlabel('样本点')
plt.suptitle('日降水数据基于 VMD 的分解结果', fontsize=14)
plt.tight_layout(rect=[0, 0, 1, 0.96])  # 留出标题空间
plt.show()
